package com.john.booter.module.file;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.john.booter.plugin.ueditor.UeditorActionEnter;
import com.john.booter.plugin.ueditor.UeditorService;
import com.john.booter.plugin.ueditor.util.UnicodeUtil;

@RestController
@RequestMapping("/ueditor")
public class UEditorCtrl {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	//@Resource(name="UeditorServiceFastdfsImpl")
//	@Resource(name="UeditorServiceQiniuImpl")
	@Resource(name="UeditorServiceCommonImpl")
	private UeditorService ueditoreService;

	@RequestMapping(value = "execute")
	public String execute(HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {
		String rootPath = request.getServletContext().getRealPath("/");
		String resultMsg = new UeditorActionEnter(request, rootPath, this.ueditoreService).exec();
		resultMsg = UnicodeUtil.fromUnicode(resultMsg);
		logger.debug("ueditor execute ... resultMsg:" + resultMsg);

		return resultMsg;
	}

}
